package com.StarStudio.Controller;

import com.StarStudio.Domain.Annualoutput;
import com.StarStudio.Domain.HttpStatusCode;
import com.StarStudio.Domain.MessageConstant;
import com.StarStudio.Domain.Result;
import com.StarStudio.Service.AnnualOutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/output")
public class AnnualOutputController {

    @Autowired
    private AnnualOutputService annualoutputService;

    @GetMapping("/{zoneId}")
    public Result getByZoneId(@PathVariable Integer zoneId){
        List<Annualoutput> annualOutputList = null;
        try {
            annualOutputList = annualoutputService.getByZoneId(zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.ANNUAL_OUTPUT_QUERY_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.ANNUAL_OUTPUT_QUERY_SUCCESS, annualOutputList);
    }

    @PostMapping("/{zoneId}")
    public Result add(@RequestBody Annualoutput annualoutput, @PathVariable int zoneId) {
        try {
            annualoutputService.add(annualoutput,zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.ANNUAL_OUTPUT_ADD_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.ANNUAL_OUTPUT_ADD_SUCCESS);
    }

    @PutMapping("")
    public Result update(@RequestBody Annualoutput annualoutput){
        try {
            annualoutputService.update(annualoutput);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR,MessageConstant.ANNUAL_OUTPUT_UPDATE_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.ANNUAL_OUTPUT_UPDATE_SUCCESS);
    }

    @DeleteMapping("/{annualOutputId}")
    public Result delete(@PathVariable int annualOutputId){
        try {
            annualoutputService.delete(annualOutputId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.ANNUAL_OUTPUT_DELETE_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.ANNUAL_OUTPUT_DELETE_SUCCESS);
    }

}
